#include "SDLEngine.h"

SDLEngine* SDLEngine::instance = NULL;

SDLEngine::SDLEngine()
	:isInitialized(false)
{
}
SDLEngine::~SDLEngine()
{
	isInitialized = false;
}
int SDLEngine::Initialize( const std::string screenCaption
						 , const int screenWidth
						 , const int screenHeight)
{
	if( SDL_Init( SDL_INIT_EVERYTHING ) == -1 )
	{
		return 1;
	}

	screen = SDL_SetVideoMode( screenWidth, screenHeight, SCREEN_BPP, SDL_SWSURFACE );

	SDL_WM_SetCaption( screenCaption.c_str(), NULL );

	isInitialized = true;
}
void SDLEngine::Run()
{
	SDL_Event event;
	bool isRunning = true;

	bool isPressed = false;

	while(!SDLInput::GetInstance()->Quit())
	{
		SDLInput::GetInstance()->Poll();

		Update();
		Draw();
	}
}
void SDLEngine::Update()
{
	std::vector<SDLComponent*>::iterator iter;
	for(iter = SDLComponent::components.begin(); iter != SDLComponent::components.end(); iter++)
	{
		(*iter)->Update();
	}
}
void SDLEngine::Draw()
{
	std::vector<SDLComponent*>::iterator iter;
	for(iter = SDLComponent::components.begin(); iter != SDLComponent::components.end(); iter++)
	{
		(*iter)->Draw();
	}

	if(SDL_Flip( screen ) == -1)
	{
		// Throw exception
	}
}
